#ifndef _APP_SERVICE_H_
#define _APP_SERVICE_H_

#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std ;

#include "repoll.h"
#include "rtask.h"


enum SOFTWARE_TYPE
{
	DEAMON = 0,
	_19dot5_APP = 1,
	_31dot5_APP
} ;

extern short gsh_daemon_port ;
extern int gi_client_idle ;

class app_task  : public rtask
{
	public :
		app_task() :  mi_type(-1), ms_sn(""), ms_version(""), ms_vender(""){}
		~app_task()
		{
			mi_type = -1 ;
			ms_sn.clear();
			ms_version.clear();
			ms_vender.clear();
		}

		int mi_type ;
		string ms_sn;
		string ms_version;
		string ms_vender;
} ;

class app_service
{
	private :
		app_service() ;
		virtual ~app_service( ) ;

		app_service(const app_service&);
		app_service& operator=(const app_service&);
		
		void add_task(const int i_socket ) ;
		void del_task(const int i_socket);

		static void* epoll_accept_routine(void* arg) ;
		void epoll_accept_entry(void);

		static void* epoll_wait_routine(void* arg) ;
		void epoll_wait_entry(void);

		static void* epoll_clear_routine(void* arg) ;
		void epoll_clear_entry(void);

		repoll mservice_epoll ;
		map<int, app_task*> mm_task ;

	public:
		static app_service& _instance()
		{
			static app_service instance ;
			return instance ;
		}

		bool start() ;
		
		void del_task(app_task& r_task) ;
		void do_display_app_update(const string& s_new_version, const string& s_path);	
		void do_control_app_update(const string& s_new_version, const string& s_path);	
		void write(const string& s_data);

		void set_control_online(app_task* r_task=NULL);
		
		app_task* mp_control_task;
		bool mb_using ;
} ;

#endif

